package com.backstage.service.Impl;

import com.backstage.pojo.dto.Message;
import com.backstage.pojo.vo.SysSelectVo;
import com.backstage.service.SysDictionaryService;
import com.backstage.service.SysUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("SysUtilService")
public class SysUtilServiceImpl implements SysUtilService {
    @Autowired
    SysDictionaryService sysDictionaryService;

    @Override
    public Message<List<SysSelectVo>> selectSex(Long id) {
        Map<String, String> user_sex = sysDictionaryService.getValues("user_sex");
        List<SysSelectVo> list = new ArrayList<>();
        user_sex.forEach((k, v) -> {
            SysSelectVo sysSelectVo1 = new SysSelectVo();
            sysSelectVo1.setId(Long.valueOf(k));
            sysSelectVo1.setText(v);
            if (sysSelectVo1.getId() == id) {
                sysSelectVo1.setSelected(true);
            }
            list.add(sysSelectVo1);
        });
        return Message.successMessage(1L, list);

    }

    @Override
    public Message<List<SysSelectVo>> selectState(Long id) {
        Map<String, String> user_sex = sysDictionaryService.getValues("user_state");
        List<SysSelectVo> list = new ArrayList<>();
        user_sex.forEach((k, v) -> {
            SysSelectVo sysSelectVo1 = new SysSelectVo();
            sysSelectVo1.setId(Long.valueOf(k));
            sysSelectVo1.setText(v);
            if (sysSelectVo1.getId() == id) {
                sysSelectVo1.setSelected(true);
            }
            list.add(sysSelectVo1);
        });
        return Message.successMessage(1L, list);
    }

    @Override
    public Message<List<SysSelectVo>> selectType(Long id) {
        Map<String, String> user_sex = sysDictionaryService.getValues("sys_type");
        List<SysSelectVo> list = new ArrayList<>();
        user_sex.forEach((k, v) -> {
            SysSelectVo sysSelectVo1 = new SysSelectVo();
            sysSelectVo1.setId(Long.valueOf(k));
            sysSelectVo1.setText(v);
            if (sysSelectVo1.getId() == id) {
                sysSelectVo1.setSelected(true);
            }
            list.add(sysSelectVo1);
        });
        return Message.successMessage(1L, list);
    }

    @Override
    public Message<List<SysSelectVo>> selectUserInfoType(Long id) {
        Map<String, String> user_sex = sysDictionaryService.getValues("user_info_type");
        List<SysSelectVo> list = new ArrayList<>();
        user_sex.forEach((k, v) -> {
            SysSelectVo sysSelectVo1 = new SysSelectVo();
            sysSelectVo1.setId(Long.valueOf(k));
            sysSelectVo1.setText(v);
            if (sysSelectVo1.getId() == id) {
                sysSelectVo1.setSelected(true);
            }
            list.add(sysSelectVo1);
        });
        return Message.successMessage(1L, list);
    }
}
